function getDialogue(text) {
    EasyAjax.get({
        url: path + 'robotRecord/dialogue?text=' + text,
    }, function (data) {
        console.log(data);
        var data = data.data;
        var message = data.text;
        var ans = '<div class="answer"><div class="heard_img left"><img src="images/service.jpg"/></div>';
        ans += '<div class="answer_text"><p>' + message + '</p><i></i>';
        ans += '</div></div>';
        $('.speak_box').append(ans);
        for_bottom();
        return text;
    });
}

function for_bottom(){
    var speak_height = $('.speak_box').height();
    $('.speak_box,.speak_window').animate({scrollTop:speak_height},500);
}
function up_say() {
    $('.write_list').remove();
    var text = $('.write_box input').val(),
        str = '<div class="question">';
    str += '<div class="heard_img right"><img src="images/client.jpg"/></div>';
    str += '<div class="question_text clear"><p>' + text + '</p><i></i>';
    str += '</div></div>';
    if (text == '') {
        alert('请输入提问！');
        $('.write_box input').focus();
    } else {
        $('.speak_box').append(str);
        $('.write_box input').val('');
        $('.write_box input').focus();
        autoWidth();
        for_bottom();
        getDialogue(text);
    }
}

function keyup(){
    var footer_height = $('.wenwen-footer').outerHeight(),
        text = $('.write_box input').val(),
        str = '<div class="write_list">'+text+'</div>';
    if (text == '' || text == undefined){
        $('.write_list').remove();
    }else{
        $('.wenwen-footer').append(str);
        $('.write_list').css('bottom',footer_height);
    }
}
function autoWidth(){
    $('.question_text').css('max-width',$('.question').width()-60);
}
autoWidth();
document.onkeydown = function (e) { // 回车提交表单
    var theEvent = window.event || e;
    var code = theEvent.keyCode || theEvent.which || theEvent.charCode;
    if (code == 13) {
        up_say();
    }
}